package com.briup.demo.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.demo.bean.CmsCategory;
import com.briup.demo.mapper.CmsCategoryMapper;
//@service注解，表明当前类试一个Service对象。
@Service
public class CmsCategoryService {
	//@Autowired代表这个属性值需要spring容器自动注入。
	@Autowired
	private CmsCategoryMapper categoryMapper;
	
	
	public List<CmsCategory> findAll(){
		return categoryMapper.selectAll();
	}
	
	
	public int batchDelete(String[] ids) {
		//如果数组不是空的，并且数组中存放的数据个数>0
		if(ids!=null&&ids.length>0) {
			return categoryMapper.batchDeleteByIds(ids);
		}
		return 0;
	}
	
	public int deleteById(String id) {
		return categoryMapper.deleteByPrimaryKey(id);
	}
	
	
	public void saveOrUpdate(CmsCategory category) {
		if(category.getId()!=null) {
			categoryMapper.updateByPrimaryKey(category);
		}else {
			category.setId(UUID.randomUUID().toString());
			categoryMapper.insert(category);
		}
	}
}
